<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"
    />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script src="./js/lib.js"></script>
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="">商品管理</a>
            <a href="">常规产品</a>
            <a>
                <cite>添加新产品</cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);"
            title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </div>
    <div class="x-body">
        <form action="" class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>活动名-简体
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="ptlNameCn" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>活动名-繁体
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="ptlNameTw" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>活动名-英文
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="ptlNameEn" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>描述-简体
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="introCn" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>描述-繁体
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="introTw" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>描述-英文
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="introEn" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>活动类型
                </label>
                <div class="layui-input-block" >
                    <input name="ptl_type" type="radio" value="vip"  title="VIP 折扣" checked lay-filter="ptl">
                    <input name="ptl_type" type="radio" value="fullSubtraction" title="订单满减" lay-filter="ptl">
                    <input name="ptl_type" type="radio" value="discount" title="普通折扣" lay-filter="ptl">
                    <input name="ptl_type" type="radio" value="deductible" title="抵扣码抵扣(抵扣金额由抵扣码决定)" lay-filter="ptl">
                </div>
            </div>
            <div class="layui-form-item show-box-item" show-type="vip">
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>折扣力度
                </label>
                <div class="layui-input-inline">
                    <input type="number" id="vip"  autocomplete="off" class="layui-input" placeholder="请输入1-99">
                </div>
            </div>
            <div class="layui-form-item show-box-item x-dis-none" show-type="fullSubtraction">
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>满足金额
                </label>
                <div class="layui-input-inline">
                    <input type="number" id="fullAmount"  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item show-box-item x-dis-none" show-type="discount">
                <label for="" class="layui-form-label">
                    <span class="x-red">*</span>折扣力度
                </label>
                <div class="layui-input-inline">
                    <input type="number" id="discount"  autocomplete="off" class="layui-input" placeholder="请输入1-99">
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" lay-filter="sbt_form" lay-submit="submit" id="sbt">
                    确定提交
                </button>
            </div>
        </form>
    </div>

    <script>
        var layer = layui.layer;
        var aId = Cookies.get('kplus-helmetAdminId');
        var aToken = Cookies.get('kplus-helmetAdminToken');
                
        layui.use('form', function () {
            var form = layui.form;
            form.on('radio(ptl)', function (data) {
                $('.show-box-item').addClass('x-dis-none');
                $('.show-box-item[show-type="'+ data.value+'"]').removeClass('x-dis-none');
            });
            form.on('submit(sbt_form)', function (data) { 
                var ptlNameCn = $('#ptlNameCn').val();
                var ptlNameTw = $('#ptlNameTw').val();
                var ptlNameEn = $('#ptlNameEn').val();
                var introCn = $('#introCn').val();
                var introTw = $('#introTw').val();
                var introEn = $('#introEn').val();
                var num = $('#'+ data.field.ptl_type+'').val()
                var ptlName = 'cn:'+ ptlNameCn+'|en:'+ ptlNameEn+'|tw:'+ ptlNameTw;
                var ptlIntro = 'cn:' + introCn + '|en:' + introEn + '|tw:' + introTw;
                var ptlType = data.field.ptl_type;
                
                $.ajax({
                    url:bAsEuRl + uRlS.ptl,
                    type:'PUT',
                    data:{
                        'aId': aId,
                        'aToken': aToken,
                        'name': ptlName,
                        'intro': ptlIntro,
                        'type': ptlType,
                        'num': num
                    },
                    success: function (data) {
                        if(data.msg.code == 200){
                            layer.msg(data.data.msg, { time:2000});
                            form.render();
                        }else{
                            layer.msg(data.msg.msg, { time: 2000 });
                        }
                      },
                    error: function (data) {
                        layer.msg('系统发生严重错误，请联系维护人员', { time: 2000 });
                      }
                })


                return false;
            })
        })
                

    </script>
</body>

</html>